package dao

import (
	"github.com/jinzhu/gorm"
	"pojo/model"
)

/*
 * 客户明细数据库访问对象
 */
type UserBalancesDao struct {
	db *gorm.DB
}

/*
 * 构造新的客户明细需要传入数据库的对象
 */
func NewUserBalancesDao(db *gorm.DB) *UserBalancesDao {
	return &UserBalancesDao{
		db: db,
	}
}

/*
 * 保存客户明细信息
 */
func (this *UserBalancesDao) InsertUserBalances(userBalances *model.UserBalanceStatement) (int64, error) {
	// 插入
	result := this.db.Save(userBalances)
	return result.RowsAffected, result.Error
}

// 根据客户id分页查询 客户明细信息
func (this *UserBalancesDao) GetUserBalancesList( page, limit int32,user_id uint) ([] *model.UserBalanceStatement, error) {
	userBalances := make([] *model.UserBalanceStatement, limit)
	result := this.db.Limit(limit).Offset((page - 1) * limit).Find(&userBalances).Where("user_id",user_id)
	return userBalances, result.Error
}